import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

import '../../model/space_item.dart';
import 'fileSpace_helper.dart';

typedef FileDeleteCallback = void Function(SpaceItem r1);

class FileSpacePanel extends StatefulWidget {
  @override
  FileSpacePanel(this.title, this.spaceId);

  final String spaceId;
  final String title;

  @override
  FileSpacePanelState createState() => new FileSpacePanelState();
}

class FileSpacePanelState extends State<FileSpacePanel> {
  List<SpaceItem> RList = <SpaceItem>[];
  bool isEnd = false;
  ScrollController _scrollController = new ScrollController();
  bool firstLoading = true;
  int pageSize = 100;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    getNewer();
  }

  Future<Null> getNewer() async {
    var list1 = await SpaceItem.GetList(widget.spaceId, 0, 1, pageSize);

    setState(() {
      firstLoading = false;
      RList = list1;
    });
  }

  List<Widget> getWidgetList() {
    List<Widget> list1 = <Widget>[];
    list1.add(ListTile(
      title: Text(widget.title),
    ));

    list1.add(Divider(
      height: 0.0,
    ));

    for (var a in RList) {
      list1.add(FileSpaceHelper.fileCard3(context, a));
      list1.add(Divider(
        height: 0.0,
      ));
    }

    return list1;
  }

  @override
  Widget build(BuildContext context) {
    if (RList == null) return new Container();

    return firstLoading == true
        ? Center(
            child: SpinKitCircle(
            color: Colors.blue,
          ))
        : Container(
            // margin: EdgeInsets.only(top: 8.0),
            child: Column(
            children: getWidgetList(),
          ));
  }
}
